package Frame.screen;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import FCRendering.ImageUtil;
import Frame.sayoptional.SayTextAndOption;
import VWorldGameStudio.FCPlayerInfo;
import Function.FCMutilPlayCache;

import java.awt.*;

import static FCRendering.FCRMaster.charLib;
import static FCRendering.FCRMaster.fcv;

//NPC对话，物品选项等等,以及对话商店
public class OptionalSayScreen extends IScreen{
    private DefaultShopScreen shopScreen = new DefaultShopScreen();
    Font font4,font3;
    @Override
    public void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster) {

        // 渲染对话
        if (fcv.isOpenSay()) {
            if (fcv.getSayText() != null) {
                g.setColor(Color.white);
                g.setFont(font4);
                //如果有人则显示这里
                if(fcv.getSayNpcName() != null && !fcv.getSayNpcName().equals("null")){
                    g.drawImage(ImageUtil.getImage("gamesayframe"), (int) (532 * fcv.getProportion()),
                            (int) (732 * fcv.getProportion()), (int) (856 * fcv.getProportion()), (int) (192 * fcv.getProportion()), this);
                    g.drawImage(charLib.getCharacterOfName(fcv.getSayNpcName()).getActionImage(0, 0, false),
                            (int) (546 * fcv.getProportion()), (int) (746 * fcv.getProportion()), (int) (164 * fcv.getProportion()),
                            (int) (164 * fcv.getProportion()), this);
                    g.drawString(fcrMaster.getLangLib().getNameOfId(fcv.getSayText()[0]), (int) (720 * fcv.getProportion()),
                            (int) (780 * fcv.getProportion()));
                } else {//物品调查显示这里
                    g.drawImage(ImageUtil.getImage("gamefightsayframe"), (int) (532 * fcv.getProportion()),
                            (int) (732 * fcv.getProportion()), (int) (856 * fcv.getProportion()), (int) (192 * fcv.getProportion()), this);
                    g.drawString(fcrMaster.getLangLib().getNameOfId(fcv.getSayText()[0]), (int) (682 * fcv.getProportion()),
                            (int) (780 * fcv.getProportion()));
                }
            }
            if (fcv.getSayNpcSelectMenu().size() > 0) {
                g.setColor(Color.black);
                g.setFont(font3);
                g.drawImage(ImageUtil.getImage("gamesayselectmenuhead"), (int) (1388 * fcv.getProportion()),
                        (int) (732 * fcv.getProportion()), (int) (184 * fcv.getProportion()), (int) (19 * fcv.getProportion()), this);
                for (int i = 0; i < fcv.getSayNpcSelectMenu().size(); i++) {
                    g.drawImage(ImageUtil.getImage("gamesayselectmenubody"), (int) (1388 * fcv.getProportion()),
                            (int) ((751 + i * 44) * fcv.getProportion()), (int) (184 * fcv.getProportion()),
                            (int) (44 * fcv.getProportion()), this);
                    g.drawImage(ImageUtil.getImage("gamesayselectbutton"), (int) (1406 * fcv.getProportion()),
                            (int) ((753 + i * 44) * fcv.getProportion()), (int) (149 * fcv.getProportion()),
                            (int) (40 * fcv.getProportion()), this);
                    SayTextAndOption op = fcv.getSayNpcSelectMenu().get(i);
                    if(op.optionType.equals("player")){
                        //这里是显示玩家列表
                        FCPlayerInfo p = FCMutilPlayCache.findPlayerByName(op.optionTextId.split(",")[1],op.optionTextId.split(",")[0]);
                        g.drawString(p.getChName(),(int) (1435 * fcv.getProportion()), (int) ((778 + i * 44) * fcv.getProportion()));
                    }else {
                        g.drawString(fcrMaster.getLangLib().getNameOfId(fcv.getSayNpcSelectMenu().get(i).optionTextId),
                                (int) (1435 * fcv.getProportion()), (int) ((778 + i * 44) * fcv.getProportion()));
                    }
                    if (fcv.getSayMouseEnterSelectNum() == i) {
                        g.setColor(new Color(163, 163, 163));
                        g.fillRect((int) (1409 * fcv.getProportion()), (int) ((756 + i * 44) * fcv.getProportion()),
                                (int) (16 * fcv.getProportion()), (int) (34 * fcv.getProportion()));
                        g.setColor(Color.black);
                    }
                }
                g.drawImage(ImageUtil.getImage("gamesayselectmenufoot"), (int) (1388 * fcv.getProportion()),
                        (int) ((751 + fcv.getSayNpcSelectMenu().size() * 44) * fcv.getProportion()), (int) (184 * fcv.getProportion()),
                        (int) (19 * fcv.getProportion()), this);
            }
            if (fcv.isOpenSayShop()) {// 对话商店
                shopScreen.paintComponent(g, fcrMaster);
            }
        }
    }

    @Override
    protected void setBounds() {
        font4 = new Font(FCRConstants.FONT_ELEGANT_BLACK, 0, (int) (22 * fcv.getProportion()));
        font3 = new Font(FCRConstants.FONT_ELEGANT_BLACK, 0, (int) (20 * fcv.getProportion()));
        shopScreen.dipatchSetBounds();
    }
}
